package dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import dao.IServiceDAO;
import entity.CstService;

public class IServiceDAOImpl extends HibernateDaoSupport implements IServiceDAO{

	
	private String hql;

	@Override
	public void addService(CstService cstservice) throws Exception {
		this.getHibernateTemplate().saveOrUpdate(cstservice);
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<CstService> queryAllService() {
		hql = "from CstService";
		//sessionFactory--session --Query.setString()
		return this.getHibernateTemplate().execute(new HibernateCallback(){

			@Override
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session.createQuery(hql);
				return query.list();//query.list()
			}
			
		});
	}

	@Override
	public void delete(CstService cstservice) throws Exception {
		this.getHibernateTemplate().delete(cstservice);
	}

}
